package com.spic.business.informatization.accounting.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spic.business.informatization.accounting.domain.MeetingFile;
import com.spic.business.informatization.accounting.mapper.MeetingFileMapper;

import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;
@RestController
@RequestMapping("/informatization/file/accounting")
public class MeetingFileController extends BaseController {
    @Autowired
    private MeetingFileMapper fileMapper;



    /**
     * 查询应急预案附件列表
     */
    @GetMapping("/file/list")
    public TableDataInfo list(MeetingFile file)
    {
        startPage();
        List<MeetingFile> list = fileMapper.selectList(
                new LambdaQueryWrapper<MeetingFile>()
                        .eq(MeetingFile :: getMeetingAccountingId, file.getMeetingAccountingId())
        );
        return getDataTable(list);
    }


    /**
     * 新增应急预案附件
     */
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping("/file")
    public AjaxResult add(@RequestBody MeetingFile file)
    {
        return toAjax(fileMapper.insert(file));
    }

    /**
     * 修改应急预案附件
     */
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping("/file")
    public AjaxResult edit(@RequestBody MeetingFile file)
    {
        return toAjax(fileMapper.updateById(file));
    }

    /**
     * 删除应急预案附件
     */
    @Log(title = "附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/files/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(fileMapper.deleteById(id));
    }
}
